﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation.Collections;

namespace XiaoweiUWP
{
    public class ApplicationModel
    {
        private static readonly Lazy<ApplicationModel> LazyInstance = new Lazy<ApplicationModel>(() =>
        {
            return new ApplicationModel();
        }, LazyThreadSafetyMode.ExecutionAndPublication);

        public static ApplicationModel Instance { get { return LazyInstance.Value; } }

        private ApplicationModel()
        {

        }

        public void InitMvaService()
        {
            Services.MVAWakeUpService.Instance.Init();
            Services.MVAWakeUpService.Instance.WakeupConfirmed += Instance_WakeupConfirmed;
            Services.MVAWakeUpService.Instance.WakeupRejected += Instance_WakeupRejected;
        }

        private void Instance_WakeupRejected()
        {

        }

        private void Instance_WakeupConfirmed()
        {
            if(isInited)
            {
                Services.AppServiceManager.Instance.SendMessage(new ValueSet { { "Request", "MvaWakeupConfirmed" } });
            }
            else{
                Init();
            }
        }

        private bool isInited=false;

        public void Init()
        {
            if(isInited)
            {
                return;
            }
            isInited = true;
            AppServiceResponseHandlers.AppServiceResponseRegister.RegisterFunctions();
            _ = Services.AppServiceManager.Instance.ReOpenAppService();
            _ = Services.AlarmService.Instance;
        }
    }
}
